package com.tarena.lbs.common.utils;

import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import org.mindrot.jbcrypt.BCrypt; // 引入BCrypt

public class MD5Util {


    public static void main(String[] args) {
        //BCrypt.checkpw(password, user.getPassword());
        boolean rs=BCrypt.checkpw("123456", "$2a$10$n5HSgeSA7vEk02iBvRrZcOy00KvZjigrbX.YTOGepDbZCpsEtfxg.");
        System.out.println(rs);
        //System.out.println(getMd5("123456"));
        //System.out.println(getMd5("123456"));
        //$2a$10$n5HSgeSA7vEk02iBvRrZcOy00KvZjigrbX.YTOGepDbZCpsEtfxg.
    }

    public static String getMd5(String input) {
        String encryptedPassword=null;
        try {
            // 2. 对密码进行BCrypt加密（核心步骤）
            //String rawPassword = param.getPassword(); // 前端传入的明文密码
            encryptedPassword = BCrypt.hashpw(input, BCrypt.gensalt()); // 加

//            MessageDigest md = MessageDigest.getInstance("MD5");
//            byte[] messageDigest = md.digest(input.getBytes());
//            BigInteger no = new BigInteger(1, messageDigest);
//            String hashtext = no.toString(16);
//            while (hashtext.length() < 32) {
//                hashtext = "0" + hashtext;
//            }
//            return hashtext;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return encryptedPassword;

    }






}
